package com.kunbo.cn.controller.system;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * 首页所需接口
 * <p>Title: HomePageController</p>
 * <p>Description: </p>
 * <p>Company: www.kunbo.cn</p> 
 * @author	yang'f
 * @date	2019年3月19日下午11:35:42
 * @version 1.0
 */
@RestController
@RequestMapping("/index/")
public class HomePageController {
	@Autowired
	private JdbcTemplate jdbc;
	@RequestMapping("getTotal")
	public List<Map<String,Object>> getTotalCustom() {
		List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
		Map<String,Object> cusMap = new HashMap<String, Object>();
		Map<String,Object> purMap = new HashMap<String, Object>();
		Map<String,Object> salMap = new HashMap<String, Object>();
		Map<String,Object> carMap = new HashMap<String, Object>();
		String sqlCustom = "select count(id) total from business_customer_manage";
		String sqlPurchase = "select SUM(number_of_contracts) contract_for_purchase_total "
				+ "from bussiness_purchasing_order_manager";
		String sqlSales = "select SUM(contract_all_amount) sales_contract_total  "
				+ "from  business_sale_order_manage";
		String sqlArrivalOfGoodsCar = "select COUNT(id) from  business_notice_of_arrival "
				+ "where notice_state = 10";
		String sqlPickUpGoodsCar = "select COUNT(id) from business_delivery_notice_manage "
				+ "where state = 10";
		String customTotal = jdbc.queryForObject(sqlCustom, String.class);//获取客户总数
		String contractForPurchaseTotal = jdbc.queryForObject(sqlPurchase, String.class);
		String salesContractTotal = jdbc.queryForObject(sqlSales, String.class);
		Integer arrivalOfGoodsCarTotal = jdbc.queryForObject(sqlArrivalOfGoodsCar, Integer.class);//获取到货通知单已出厂车辆数
		Integer pickUpGoodsCarTotal = jdbc.queryForObject(sqlPickUpGoodsCar, Integer.class);//获取提货通知单已出厂车辆数
		String carFlux =(arrivalOfGoodsCarTotal+pickUpGoodsCarTotal)+"";
		cusMap.put("customTotal", customTotal);
		purMap.put("contractForPurchaseTotal", contractForPurchaseTotal);
		salMap.put("salesContractTotal", salesContractTotal);
		carMap.put("carFlux", carFlux);
		list.add(cusMap);
		list.add(purMap);
		list.add(salMap);
		list.add(carMap);
		return list;
		
	}

}
